<template>
  <div id="login">
    <div class="login-box center-block">
      <el-card style="width: 400px;">
        <div slot="header" class="clearfix">
          <h3 class="text-center">demo-client</h3>
        </div>
        <el-tabs v-model="isAdmin" type="border-card">
          <el-tab-pane label="登录" name="0">
            <login-item @login="login"/>
          </el-tab-pane>
          <el-tab-pane label="管理界面" name="1">
            <login-item @login="login"/>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
  import loginItem from './login-item'

  export default {
    components: {
      loginItem
    },
    name: "login",
    data() {
      return {
        isAdmin: '0',
      }
    },
    methods: {
      login(form) {

        let password = this.common.password(form.password)
        this.common.request({
          url: 'sys/userInfo/login',
          param: {
            loginName: form.loginName,
            password: password
          },
          success: (res) => {
            if (res.code == 1) {
              sessionStorage.setItem("token", res.token)
              this.$store.commit('set_user_info', res.data.rows[0])
              sessionStorage.setItem("user",JSON.stringify(res.data.rows[0]))
              // this.getLoginMenu()
              if (this.isAdmin == 1) {
                vueRouter.replace('/a')
              }else{
                vueRouter.replace('/f')
              }
            }
          }
        })
      },

    }
  }
</script>

<style scoped>
  #login {
    width: 100%;
    height: 100%;
    background-color: #7bb9d8;
    position: absolute;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
